import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";
import router from "../router";

Vue.use(Vuex);

export default new Vuex.Store({
  state: { userInfo: "" },
  mutations: {
    GetUser(state, b) {
      state.userInfo = b;
      // console.log(a, b);
    }
  },
  actions: {
    async getUser(a) {
      await axios
        .post("/students/getUserInfo")
        .then(({ data }) => {
          let res = data["data"][0];
          a.commit("GetUser", res);
        })
        .catch((reason) => {
          this._vm.$message.error("登录已过期,请重新登录");
          // alert("登录已过期,请重新登录");
          router.push("/login");
          console.log("发送错误", reason);
        });
    }
  },
  modules: {}
});
